package it.polimi.swimv2.util;

public class UserDataValidator {

	public static boolean emailIsValid(String email) {
		if (email == null || !email.matches(".+@.+")) {
			return false;
		}
		return true;
	}

	public static boolean phoneIsValid(String phone) {
		if (phone == null || !phone.matches("[\\d]*")) {
			return false;
		}

		return true;
	}

	public static boolean cityIsValid(String city) {
		if (city == null || !city.matches("[a-zA-Z\\s]*")) {
			return false;
		}
		return true;
	}

	public static boolean nameIsValid(String firstName, String surname) {
		if(firstName==null||surname==null){
			return false;
		}
		if(!firstName.matches("[a-zA-Z][\\sa-zA-Z]*")||!surname.matches("[a-zA-Z][\\sa-zA-Z]*")){
			return false;
		}
		return true;
		
	}

	/**
	 * Method for the validation of a password. A password is valid when it is
	 * alphanumeric and at least composed by six characters.
	 * 
	 * @param pwd
	 *            the password to be checked.
	 * @return true if pwd is a valid password for the application.
	 */
	public static boolean passwordIsValid(String pwd) {
		return pwd.matches("[a-zA-Z0-9]{6,}");

	}

	public static boolean usernameIsValid(String username) {
		
		return (username!=null&&username.matches("[a-zA-Z0-9]+") );
	}
}
